package com.itheima;

import java.util.Scanner;

public class ArrayDemo {
    public static void main(String[] args) {
//        int[] arr1 = {1, 2, 3, 4, 5}; //简洁的写法
//        int [] arr2 = new int[] {1, 2, 3, 4, 5}; //完整的写法
//        int arr3[] = {1, 2, 3, 4, 5}; //简单的写法
//        System.out.println(arr3);
//        int[] arr = {1, 2, 3, 4, 5};
//        getMax(arr);
//        getMin(arr);
        System.out.println("请输入数组的长度");
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double[] arr1 = getArr(n);
        getTotal(arr1);
    }
    public static void getMax(int[] arr) {
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        System.out.println("最大值是：" + max);
    }
    public static void getMin(int[] arr) {
        int min = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] < min) {
                min = arr[i];
            }
        }
        System.out.println("最小值是：" + min);
    }

    public static void getTotal(double arr[]){
        double total = 0;
        for (int i = 0; i < arr.length; i++) {
            total += arr[i];
        }
        System.out.println("总和是：" + total);
        System.out.println("平均值是：" + total/arr.length);
    }

    public static double[] getArr(int n) {
        Scanner sc = new Scanner(System.in);
        double[] arr = new double[n];
        for (int i = 0; i < n; i++) {
            System.out.println("请输入第" + (i+1) + "个数");
            arr[i] = sc.nextDouble();
        }
        return arr;
    }
}
